import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model
from sklearn.preprocessing import PolynomialFeatures


data = pd.read_csv('prices.csv')
square = data["square"]
prices = data["prices"]
length = len(square)

square = np.array(square).reshape([length,1])
prices = np.array(prices).reshape([length,1])

minX = min(square)
maxX = max(square)

X = np.arange(minX,maxX).reshape([-1,1])
# # -----------------线性回归处理------------
# linear = linear_model.LinearRegression
#
# linear = linear_model.LinearRegression()
# linear.fit(square,prices)
#

# 多项式预测
poly_reg = PolynomialFeatures(degree=2)
X_poly = poly_reg.fit_transform(square)
lin_reg_2 = linear_model.LinearRegression()
lin_reg_2.fit(X_poly,prices)

plt.scatter(square,prices)
plt.plot(X,lin_reg_2.predict(poly_reg.fit_transform(X)))
plt.show()